<template>
  <div class="min-h-screen bg-gray-50 flex items-center justify-center p-6">
    <div class="bg-white rounded-2xl shadow-sm w-full max-w-xl p-8">
      <h1 class="text-2xl font-bold text-gray-900 mb-2">账号验证</h1>
      <p class="text-gray-600 mb-8">通过输入账号密码完成管理员验证</p>

      <form @submit.prevent="submit">
        <div class="mb-6">
          <label class="block text-sm font-medium text-gray-700 mb-2">手机号</label>
          <input v-model="phone" type="tel" placeholder="请输入管理员手机号" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" />
        </div>
        <div class="mb-8">
          <label class="block text-sm font-medium text-gray-700 mb-2">密码</label>
          <input v-model="password" type="password" placeholder="请输入密码" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" />
        </div>
        <div class="flex items-center justify-between">
          <button type="button" class="px-4 py-2 text-gray-600 hover:text-gray-900" @click="$router.push('/admin/login')">返回</button>
          <button type="submit" class="px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-medium">完成验证</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AdminVerifyAccount',
  data() {
    return { phone: '', password: '' }
  },
  methods: {
    async submit() {
      if (!this.phone || !this.password) { alert('请输入手机号与密码'); return }
      try {
        const res = await fetch('/api/auth/login-with-password', {
          method: 'POST', headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ phone: this.phone, password: this.password })
        })
        const result = await res.json()
        if (result.success) {
          localStorage.setItem('adminToken', result.data.userId || 'verified')
          localStorage.setItem('adminInfo', JSON.stringify(result.data.userInfo || { role: 'admin' }))
          this.$router.push('/admin/dashboard')
        } else {
          alert(result.message || '验证失败')
        }
      } catch (e) {
        alert('网络错误，请稍后重试')
      }
    }
  }
}
</script>


